package com.sc.pattern.passivelistener;

import com.sc.pattern.passivelistener.LifeCycleListener;

/**
 * Created  on 2018/1/6.
 *
 * @author sc
 */
public  abstract class ObservableRunnable implements Runnable {
    final protected LifeCycleListener listener;
    public ObservableRunnable(LifeCycleListener lifeCycleListener){
        this.listener = lifeCycleListener;
    }

    protected void notifyChange(RunnableEvent event){
        listener.onEvent(event);
    }
    public enum RunnableState{
        RUNNING,ERROR,DONE;
    }

    public static class RunnableEvent{
        private final RunnableState state;
        private final Thread thread;
        private final Throwable cause;

        public RunnableEvent(RunnableState state, Thread thread, Throwable cause) {
            this.state = state;
            this.thread = thread;
            this.cause = cause;
        }

        public RunnableState getState() {
            return state;
        }

        public Thread getThread() {
            return thread;
        }

        public Throwable getCause() {
            return cause;
        }
    }
}
